package com.Ruier.utils;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@Component
public class HandleHeroPosition {
    private static HashMap<String,String> map=new HashMap<>();
    static {
        map.put("1","战士");
        map.put("2","法师");
        map.put("3","刺客");
        map.put("4","辅助");
        map.put("5","坦克");
        map.put("6","射手");
    }
    public String handle(String[] position){
        if (position.length==0)return null;
        String result=new String();
        for (int i = 0; i < position.length; i++) {
            result += map.get(position[i])+"/";
        }
        return result.substring(0,result.lastIndexOf("/"));
    }
    public String[] handlePositinToInt(String position){
        String[] t=position.split("/");
        String[] res=new String[t.length];
        for (int i = 0; i < t.length; i++) {
            Iterator<Map.Entry<String,String>> iterator=map.entrySet().iterator();
            while(iterator.hasNext()){
                Map.Entry<String, String> item = iterator.next();
                if(item.getValue().equals(t[i])){
                    res[i]=item.getKey();
                }
            }
        }
        return res;
    }
}
